/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Victor;

/**
 *
 * @author robert
 */
public class PhoenixInit {
    public SpeedController frontLeftMotor;
    public SpeedController rearLeftMotor;
    public SpeedController frontRightMotor;
    public SpeedController rearRightMotor;
    public SpeedController lifterMotor;
    public SpeedController clawMotor;
    public Compressor compressor;
    public Encoder leftEncoder;
    public Encoder rightEncoder;
    public AnalogChannel lifterPotentiometer;
    public DigitalInput lifterTopLimit;
    public DigitalInput lifterBottomLimit;
    public DigitalInput clawTopLimit;
    public DigitalInput clawBottomLimit;
    public Solenoid clawPneumatic;
    public Solenoid minibotPneumatic;
    public AnalogChannel clawPotentiomemter;
    public Joystick leftStick;
    public Joystick rightStick;
    public Joystick gamePad;
    public DigitalInput lightLeft;
    public DigitalInput lightMiddle;
    public DigitalInput lightRight;
    public DigitalInput bcd1;
    public DigitalInput bcd2;
    public RobotType currentRobot;
    Const constants;
    
    public PhoenixInit(RobotType botType) {
        currentRobot = botType;
        switch(botType.value) {
            case RobotType.bot2011jag_val:
                constants = new Const2011();

                frontLeftMotor = new Jaguar(constants.LEFT_JAGUAR_1());
                rearLeftMotor = new Jaguar(constants.LEFT_JAGUAR_2());
                frontRightMotor = new Jaguar(constants.RIGHT_JAGUAR_1());
                rearRightMotor = new Jaguar(constants.RIGHT_JAGUAR_2());
                lifterMotor = new Jaguar(constants.LIFTER_JAGUAR());

                clawMotor = new Victor(constants.CLAWJAGUAR());
                compressor = new Compressor(constants.COMPSWITCH(),
                        constants.COMPRELAY());
                leftEncoder = new Encoder(constants.LEFTENCODER1(),
                        constants.LEFTENCODER2());
                rightEncoder = new Encoder(constants.RIGHTENCODER1(),
                        constants.RIGHTENCODER2());
                lifterPotentiometer = new AnalogChannel(
                        constants.LIFTERPOTENTIOMTER());
                lifterTopLimit = new DigitalInput(
                        constants.LIFTERTOPLIMITPORT());
                lifterBottomLimit = new DigitalInput(
                        constants.LIFTERBOTTOMLIMITPORT());
                clawTopLimit = new DigitalInput(constants.CLAWTOPLIMITPORT());
                clawBottomLimit = new DigitalInput(
                        constants.CLAWBOTTOMLIMITPORT());
                clawPneumatic = new Solenoid(constants.CLAWSOLENOID());
                minibotPneumatic = new Solenoid(constants.MINIBOTSOLENOID());
                clawPotentiomemter = new AnalogChannel(
                        constants.CLAWPOTENTIOMETER());
                leftStick = new Joystick(constants.LEFTJOYSTICK());
                rightStick = new Joystick(constants.RIGHTJOYSTICK());
                gamePad = new Joystick(constants.GAMEPAD());
                lightLeft = new DigitalInput(constants.LIGHTLEFT());
                lightMiddle = new DigitalInput(constants.LIGHTMIDDLE());
                lightRight = new DigitalInput(constants.LIGHTRIGHT());
                bcd1 = new DigitalInput(constants.BCD1());
                bcd2 = new DigitalInput(constants.BCD2());
                break;

            case RobotType.bot2011can_val:
                constants = new Const2011.Const2011CAN();
                try {
                    frontLeftMotor = new CANJaguar(constants.LEFT_JAGUAR_1());
                    rearLeftMotor = new CANJaguar(constants.LEFT_JAGUAR_2());
                    frontRightMotor = new CANJaguar(constants.RIGHT_JAGUAR_1());
                    rearRightMotor = new CANJaguar(constants.RIGHT_JAGUAR_2());
                    lifterMotor = new CANJaguar(constants.LIFTER_JAGUAR());
                } catch (Exception e) {
                    e.printStackTrace();
                }

                clawMotor = new Victor(constants.CLAWJAGUAR());
                compressor = new Compressor(constants.COMPSWITCH(),
                        constants.COMPRELAY());
                leftEncoder = new Encoder(constants.LEFTENCODER1(),
                        constants.LEFTENCODER2());
                rightEncoder = new Encoder(constants.RIGHTENCODER1(),
                        constants.RIGHTENCODER2());
                lifterPotentiometer = new AnalogChannel(
                        constants.LIFTERPOTENTIOMTER());
                lifterTopLimit = new DigitalInput(
                        constants.LIFTERTOPLIMITPORT());
                lifterBottomLimit = new DigitalInput(
                        constants.LIFTERBOTTOMLIMITPORT());
                clawTopLimit = new DigitalInput(constants.CLAWTOPLIMITPORT());
                clawBottomLimit = new DigitalInput(
                        constants.CLAWBOTTOMLIMITPORT());
                clawPneumatic = new Solenoid(constants.CLAWSOLENOID());
                minibotPneumatic = new Solenoid(constants.MINIBOTSOLENOID());
                clawPotentiomemter = new AnalogChannel(
                        constants.CLAWPOTENTIOMETER());
                leftStick = new Joystick(constants.LEFTJOYSTICK());
                rightStick = new Joystick(constants.RIGHTJOYSTICK());
                gamePad = new Joystick(constants.GAMEPAD());
                lightLeft = new DigitalInput(constants.LIGHTLEFT());
                lightMiddle = new DigitalInput(constants.LIGHTMIDDLE());
                lightRight = new DigitalInput(constants.LIGHTRIGHT());
                bcd1 = new DigitalInput(constants.BCD1());
                bcd2 = new DigitalInput(constants.BCD2());
                break;

            case RobotType.bot2010_val:
                constants = new Const2010();
                clawMotor = new Victor(constants.CLAWJAGUAR());
                lifterMotor = new Jaguar(constants.LIFTER_JAGUAR());

                frontLeftMotor = new Jaguar(constants.LEFT_JAGUAR_1());
                frontRightMotor = new Jaguar(constants.RIGHT_JAGUAR_1());
                rearLeftMotor = null;
                rearRightMotor = null;

                compressor = new Compressor(constants.COMPSWITCH(),
                        constants.COMPRELAY());
                leftEncoder = null;
                rightEncoder = new Encoder(constants.RIGHTENCODER1(),
                        constants.RIGHTENCODER2());
                lifterPotentiometer = new AnalogChannel(
                        constants.LIFTERPOTENTIOMTER());
                lifterTopLimit = new DigitalInput(
                        constants.LIFTERTOPLIMITPORT());
                lifterBottomLimit = new DigitalInput(
                        constants.LIFTERBOTTOMLIMITPORT());
                clawTopLimit = new DigitalInput(constants.CLAWTOPLIMITPORT());
                clawBottomLimit = new DigitalInput(
                        constants.CLAWBOTTOMLIMITPORT());
                clawPneumatic = new Solenoid(constants.CLAWSOLENOID());
                clawPotentiomemter = new AnalogChannel(
                        constants.CLAWPOTENTIOMETER());
                leftStick = new Joystick(constants.LEFTJOYSTICK());
                rightStick = new Joystick(constants.RIGHTJOYSTICK());
                gamePad = new Joystick(constants.GAMEPAD());
                lightLeft = new DigitalInput(constants.LIGHTLEFT());
                lightMiddle = new DigitalInput(constants.LIGHTMIDDLE());
                lightRight = new DigitalInput(constants.LIGHTRIGHT());
                bcd1 = new DigitalInput(constants.BCD1());
                bcd2 = new DigitalInput(constants.BCD2());
                break;
        }
    }

    /**
     * version of robot to be initialized
     */
    public static class RobotType {
        public final int value;
        private RobotType (int value) {
            this.value = value;
        }
        static final int bot2010_val = 0;
        static final int bot2011can_val = 1;
        static final int bot2011jag_val = 2;

        /// 2010 robot
        public static final RobotType bot2010 =
                new RobotType(bot2010_val);
        /// 2011 robot
        public static final RobotType bot2011can =
                new RobotType(bot2011can_val);
        ///2011 robot, using PWM Jaguars
        public static final RobotType bot2011jag =
                new RobotType(bot2011jag_val);
    }
}
